package com.jf.cloud.multishop.listener;

import com.jf.cloud.api.user.bo.RechargeNotifyBO;
import com.jf.cloud.common.rocketmq.config.RocketMqConstant;
import com.jf.cloud.common.util.Json;
import com.jf.cloud.multishop.service.ShopWalletLogService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 添加店铺钱包日志至MongoDB
 * @author 菠萝凤梨
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.UPDATE_SHOP_RECHARGE_SUCCESS_TOPIC, consumerGroup = RocketMqConstant.UPDATE_SHOP_RECHARGE_SUCCESS_TOPIC)
public class ShopRechargeSuccessConsumer implements RocketMQListener<RechargeNotifyBO> {
    private static final Logger LOG = LoggerFactory.getLogger(ShopRechargeSuccessConsumer.class);

    @Autowired
    private ShopWalletLogService shopWalletLogService;

    @Override
    public void onMessage(RechargeNotifyBO message) {
        LOG.info("店铺余额支付成功更新店铺钱包日志回调开始... message: " + Json.toJsonString(message));
        shopWalletLogService.updateRechargeSuccess(message.getBalanceLogId(), message.getPayId());
    }
}
